package com.example.dml.delegate_pattern.mvc;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Authors：gaoyang
 * @CreateTime：2021-10-28
 * @Description：todo
 */
public class DispatcherServlet extends HttpServlet {

    private void doDispatch(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String uri = request.getRequestURI();
        String mid = request.getParameter("mid");
        if ("getMemberById".equals(uri)){
            new MemberController().getMemberById(mid);
        }else if("getOrderById".equals(uri)){
            new OrderController().getOrderById(mid);
        }else {
            response.getWriter().write("404 not found");
        }
    }

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response){
        try {
            doDispatch(request,response);
        }catch (Exception e){

        }
    }
}
